package com.metaera.app.ui.fragments;

import android.os.Bundle;

import com.metaera.app.R;
import com.metaera.app.controller.presenter.SearchPresenter;
import com.metaera.app.controller.view.SynthesisSearchResultView;
import com.metaera.app.ui.core.BaseRequestFragment;

import java.util.Objects;

import androidx.fragment.app.Fragment;

/**
 * 综合搜索结果
 */
public class SynthesisSearchResultFragment extends BaseRequestFragment {

    public static Fragment newInstance(String key, int orderType, int timeType) {
        Bundle bundle = new Bundle();
        bundle.putString("keyword", key);
        bundle.putInt("orderType", orderType);
        bundle.putInt("timeType", timeType);
        SynthesisSearchResultFragment fragment = new SynthesisSearchResultFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int getLayoutId() {

        return R.layout.fragment_synthesis_search_result;
    }

    @Override
    protected void initialize(Bundle savedInstanceState) {
        Bundle arguments = getArguments();
        String keyword = Objects.requireNonNull(arguments).getString("keyword");
        int orderType = arguments.getInt("orderType");
        int timeType = arguments.getInt("timeType");

        SearchPresenter presenter = new SearchPresenter(this);
        presenter.setModelAndView(new SynthesisSearchResultView(findViewById(R.id.layout_container), keyword));
        presenter.search(keyword, orderType, timeType);
    }

    public void reset(){
        initialize(null);
    }

}
